Public Class Evaluacion

    Private idEvaluacion As Integer
    Private nota As Double
    Private idRubro As Integer
    Private idS As Integer

    Public Sub New()

    End Sub

    Public Sub New(ByVal pnota As Double)
        Me.nota = pnota
    End Sub

    Public Sub New(ByVal pideva As Integer, ByVal pnota As String, ByVal pidr As Integer, ByVal pids As Integer)
        Me.idEvaluacion = pideva
        Me.idRubro = pidr
        Me.idS = pids
        Me.validarNota(pnota)
    End Sub

    Public Sub New(ByVal pnota As String, ByVal pidr As Integer, ByVal pids As Integer)
        Me.idRubro = pidr
        Me.idS = pids
        Me.validarNota(pnota)
    End Sub

    Private Sub validarNota(ByVal pnota As String)
        If Trim(pnota) = "" Then
            Me.nota = 0
        ElseIf pnota.Length > 0 Then
            With New System.Text.RegularExpressions.Regex("\d")
                If .IsMatch(pnota) Then
                    Me.nota = CType(pnota, Double)
                Else
                    Throw New ArgumentException("Deben ser numeros!" & vbNewLine & " Ejemplo: 90")
                End If
            End With
        End If
    End Sub

    Public Sub actualizar(ByVal idEq As Integer)
        Dim id As Integer
        Dim i As Integer
        Dim notaE As Double
        Dim actual As Double
        Dim suma As Double
        Dim daNotas As DataTable = New accesoBD.TripleCDataSetTableAdapters.selectNotas_RubroTableAdapter().GetData(Me.idRubro, idEq)
        'Throw New ArgumentException("Pasa 1")
        Dim daNota As DataTable = New accesoBD.TripleCDataSetTableAdapters.selectNotaEquipo_RubroTableAdapter().GetData(Me.idRubro, idEq)
        'Throw New ArgumentException("Pasa 2")
        Dim notaEq As Double = CType(daNota.Rows.Item(0).Item(0), Double) * daNotas.Rows.Count
        For i = 0 To daNotas.Rows.Count - 1
            id = CInt(daNotas.Rows.Item(i).Item(3))
            If Not (id = idS) Then
                notaE = CType(daNotas.Rows.Item(i).Item(0), Double)
                actual = actual + notaE
                'Throw New ArgumentException(actual)
            End If
        Next
        'Throw New ArgumentException("Pasa " & actual)
        suma = actual + nota
        'Throw New ArgumentException(suma)
        'Throw New ArgumentException(notaEq)
        If (notaEq >= suma) Then
            Dim ds As New accesoBD.TripleCDataSetTableAdapters.QueriesTableAdapter
            'Throw New ArgumentException("Pasa 1")
            ds.asignarNota(Me.idS, Me.idRubro, Me.nota)
        Else
            Throw New ArgumentException("La nota asignada excede a la nota grupal")
        End If
    End Sub

    Public Sub insertese(ByVal ptipo As Integer)
        Dim ds As New accesoBD.TripleCDataSetTableAdapters.QueriesTableAdapter
        If ptipo = 1 Then
            ds.asignarNota(Me.idS, Me.idRubro, Me.nota)
        ElseIf ptipo = 2 Then
            ds.asignarNotaEquipo(Me.idS, Me.idRubro, Me.nota)
        End If
    End Sub

    Public Sub crearNota(ByVal ptipo As Integer)
        Dim ds As New accesoBD.TripleCDataSetTableAdapters.QueriesTableAdapter
        If ptipo = 1 Then
            ds.crearExamen(Me.idS, Me.idRubro, Me.nota)
        ElseIf ptipo = 2 Then
            ds.crearExamenEquipo(Me.idS, Me.idRubro, Me.nota)
        End If
    End Sub

    Public Function calcularPorcentaje(ByVal porcent As Double, ByVal valor As Double) As Double
        porcent = porcent / 100
        Dim obtenido As Double = valor * porcent
        Return obtenido
    End Function


End Class
